function byId(e){
	if(typeof(e)=="object")
	{
		return e;
	}
	return document.getElementById(e);
}

function byName(e){
	if(typeof(e)=="object")
	{
		return e;
	}
	return document.getElementsByName(e);
}
function gE(indefer){
	if(typeof(indefer)=="object")
	{
		return indefer;
	}
	return byId(indefer)?byId(indefer):byName(indefer);
}
function MForm(formId){
	this.form = formId?byId(formId):null;
	this.exData = {};
}
MForm.prototype.submit=function(method){
	this.form.method = method?method:"POST";
	this.buildData();
	this.form.submit();
}
MForm.prototype.setForm=function(formId){
	this.form=gE(formId);
}
MForm.prototype.addData=function(name,value){
	this.exData[name]=value;
}
MForm.prototype.setAction=function(action){
	this.form.action=action;
}
MForm.prototype.buildData = function(){
	var exd = this.exData;
	for(var name in exd)
	{
		if(byName(name).length==0){
			var html = "<input type=\"hidden\" value=\"" + this.exData[name] + "\" name=\"" + name + "\">";
			var obj = document.createElement(html);	
			this.form.appendChild(obj);
		}
	}
}
var _form=new MForm();

function getParentNodeByTagName(node,tagName){
	while(true){
		node=node.parentNode;
		if(node==null)return null;
		if(node.tagName==tagName)break;
		
	}
	return node;
}

function toUrl(url)
{
	if(window.android_url)//anroid访问
	{
		window.android_url.clickOnAndroid(url);
	}else{
			window.location.href=ctxPath+url;
	}
}



function getUrl(formId,url)
{
	if(formId){
		var form = document.getElementById(formId);
		var jsonObj = [];
		for(var i = 0; i < form.elements.length; i++) 
		{ 
			var e = form.elements[i]; 
			if(e.type=="button"){
				continue;
			}
			jsonObj.push(e.name+"="+e.value);
		}
		if(url.indexOf("?")==-1)
			{
			url=url+"?"+jsonObj.join("&");
			}else{
				url=url+"&"+jsonObj.join("&");
			}
		
	}
	toUrl(url);
}




function postUrl2(formId,url,redirectUrl)
{
	if(formId){
		var jsonObj = {};
		var form = document.getElementById(formId);
		for(var i = 0; i < form.elements.length; i++) 
		{ 
			var e = form.elements[i]; 
			if(e.type=="button"){
				continue;
			}
			jsonObj[e.name]=e.value;
		}
		jsonObj["_redirectUrl_"]=redirectUrl;
		var param = JSON.stringify(jsonObj); 
		alert(param);
		window.android_post.clickOnAndroid(url,param);
	}
}



function postUrl(formId,url,redirectUrl)
{
	if(formId){
		var form = document.getElementById(formId);
		if(window.android_post){
			var jsonObj = {};
			for(var i = 0; i < form.elements.length; i++) 
			{ 
				var e = form.elements[i]; 
				if(e.type=="button"){
					continue;
				}
				jsonObj[e.name]=e.value;
			}
			jsonObj["_redirectUrl_"]=redirectUrl;
			var param = JSON.stringify(jsonObj); 
			window.android_post.clickOnAndroid(url,param);
		}else{
			form.action=ctxPath+url;
			form.submit();
		}
	}
}






Array.prototype.remove=function(dx)
{
    if(isNaN(dx)||dx>this.length){return false;}
    for(var i=0,n=0;i<this.length;i++) 
    {
        if(this[i]!=this[dx])
        {
            this[n++]=this[i];
        }
    }
    this.length-=1;
}


var files = {};
var imageIds = [];
function removeImage(imageId)
{
	var images = document.getElementsByTagName("img");
	var temImgs = [];
	   for(var i=0;i<images.length;i++)
       {
              if(images[i].id && images[i].id==("_img_"+imageId))
              {
            	  images[i].parentNode.removeChild(images[i]);
              }else{
            	  temImgs.push(imageIds[i]);
              }
       } 
	   imageIds =temImgs;
}

/**
 * 提供 android相机 的callback函数 
 * @param fileId 文件ID
 * @param fileName 文件名称 
 * @param contId 文件展示的 DIV ID
 * @param fileIdItemId 准备保存的对象 字段隐藏域 例如：reply.fileIds
 */
function createImageSrc(fileId, fileName,contId,fileIdItemId) {
	if(!files[fileIdItemId])
	{
		files[fileIdItemId]=imageIds;
	}
	files[fileIdItemId].push(fileId);
	document.getElementById(fileIdItemId).value=files[fileIdItemId].join(",");
	document.getElementById(contId).innerHTML=document.getElementById(contId).innerHTML+"&nbsp;&nbsp;<img src=\""+ctxPath + fileName+"\"  id=\"_img_"+fileId+"\" onclick=\"imageSelectEvent('"+fileId+"','preview','"+fileIdItemId+"');\"/>";
	/**
	var mg = document.createElement("img");
	mg.id="_img_"+fileId;
	mg.attachEvent("onclick", function(){
		imageSelectEvent("'"+fileId+"'","preview");
	});
	
	mg.src = ctxPath + fileName;
	document.getElementById(contId).appendChild(mg);
	
	**/
}

/**
 * 
 * @param contId 文件展示的 DIV ID
 * @param fileIdItemId fileIdItemId 准备保存的对象 字段隐藏域 例如：reply.fileIds
 */
function callAndroidCamera(contId,fileIdItemId) {
	if(window.android_carema)
		{
			window.android_carema.clickOnAndroid(contId,fileIdItemId);
		}else{
			alert("请下载客户端！");
		}
}

function to_detail_guide(url){
	if(window.android_detail)//anroid访问
	{
		window.android_detail.clickOnAndroid(url);
	}else{
			window.location.href=url;
	}
}

function toTopicDetail(url)
{
	if(window.android_topic_detail)//anroid访问
	{
		window.android_topic_detail.clickOnAndroid(url);
	}else{
			window.location.href=url;
	}
}

function issureArticle() {
	/**
	document.getElementById("post.fileIds").value="";
	if(files["post.fileIds"].length>0)
	{
		//byId("post.fileIds").value=imageIds.join("|");
		document.getElementById("post.fileIds").value=files["post.fileIds"].join(",");
	}
	***/
	
	
	
	postUrl("postContent",postContent.action,ctxPath+"/post/myPostes");
//	byId("postContent").submit();
}







